package com.gss.security.service;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import com.gss.security.domain.UserDetailsDTO;


public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler{
	
	
	
	private AuthenticationService userManagementService;
	
	
	public CustomAuthenticationFailureHandler(){
		super();
	}
	
	
	public AuthenticationService getUserManagementService() {
		return userManagementService;
	}

	public void setUserManagementService(AuthenticationService userManagementService) {
		this.userManagementService = userManagementService;
	}
	
	
	
	@Override
	public void onAuthenticationFailure(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse, AuthenticationException authException)
			throws IOException, ServletException {
		UserDetailsDTO detailsDTO = (UserDetailsDTO)authException.getExtraInformation();
		if(null != detailsDTO)
			userManagementService.accountLocked(detailsDTO);
		
		super.onAuthenticationFailure(httpServletRequest, httpServletResponse, authException);
	}

}
